import ast
import json
from datetime import datetime

from django.http import JsonResponse
from django.views import View

from lapi_app.models.task_case.task import Task


class Single_task(View):

    def post(self, request, *args, **kwargs):
        data = json.loads(request.body)
        task_id = data["task_id"]
        tasks = Task.objects.filter(id=task_id)
        task_list = [
            {
                "task_name": task.task_name,
                "task_time": task.task_time,
                "task_hour": task.task_hour,
                "task_week_days": task.task_week_days,
                "task_week_times": task.task_week_times,
                "task_cases": task.task_case,
                "result_id": task.result_id,
                "devices": task.devices_list,
                "task_status": task.task_status,
                "ding_talk": task.ding_talk,
                "task_type": str(task.task_type),
                "task_description": task.task_description,
                "run_type": task.run_type,
            }
            for task in tasks
        ]
        return JsonResponse({
            "code": 200,
            "message": "获取任务成功",
            "content": task_list
        })
